using System;
using System.Collections.Generic;
using System.Text;
using Fireball.Docking;
using Fireball.CodeEditor;
using GLuaR.Classes.Workspace;

using System.Windows.Forms;

namespace GLuaR.Windows.DockingWindows
{
    class CodeTab : DockableWindow
    {
        public Fireball.Windows.Forms.CodeEditorControl editor;
        private System.ComponentModel.IContainer components;
        public Fireball.Syntax.SyntaxDocument document;

    public CodeTab(OpenedFile file)
    {
        InitializeComponent();

        switch( GetFileType( file.Name ) )
        {
            case "txt":
                Fireball.CodeEditor.SyntaxFiles.CodeEditorSyntaxLoader.SetSyntax(editor, Fireball.CodeEditor.SyntaxFiles.SyntaxLanguage.Text);
                break;

            case "lua":
            default:
                Fireball.CodeEditor.SyntaxFiles.CodeEditorSyntaxLoader.SetSyntax(editor, Fireball.CodeEditor.SyntaxFiles.SyntaxLanguage.Lua);
                break;
        }
        editor.Open(file.FullName);
        Tag = file;

    }

    private string GetFileType(string filename)
    {
       return filename.Substring(filename.Length - 3, 3).ToLower();
    }

        public void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            Fireball.Windows.Forms.LineMarginRender lineMarginRender1 = new Fireball.Windows.Forms.LineMarginRender();
            this.editor = new Fireball.Windows.Forms.CodeEditorControl();
            this.document = new Fireball.Syntax.SyntaxDocument(this.components);
            this.SuspendLayout();
            // 
            // editor
            // 
            this.editor.ActiveView = Fireball.Windows.Forms.CodeEditor.ActiveView.BottomRight;
            this.editor.AllowBreakPoints = false;
            this.editor.AutoListPosition = null;
            this.editor.AutoListSelectedText = "a123";
            this.editor.AutoListVisible = false;
            this.editor.ChildBorderStyle = Fireball.Windows.Forms.ControlBorderStyle.None;
            this.editor.CopyAsRTF = false;
            this.editor.Dock = System.Windows.Forms.DockStyle.Fill;
            this.editor.Document = this.document;
            this.editor.InfoTipCount = 1;
            this.editor.InfoTipPosition = null;
            this.editor.InfoTipSelectedIndex = 1;
            this.editor.InfoTipVisible = false;
            lineMarginRender1.Bounds = new System.Drawing.Rectangle(19, 0, 19, 16);
            this.editor.LineMarginRender = lineMarginRender1;
            this.editor.Location = new System.Drawing.Point(0, 0);
            this.editor.LockCursorUpdate = false;
            this.editor.Name = "editor";
            this.editor.ParseOnPaste = true;
            this.editor.Saved = false;
            this.editor.ShowScopeIndicator = false;
            this.editor.ShowTabGuides = true;
            this.editor.Size = new System.Drawing.Size(680, 383);
            this.editor.SmoothScroll = true;
            this.editor.SplitView = false;
            this.editor.SplitviewH = -4;
            this.editor.SplitviewV = -4;
            this.editor.TabGuideColor = System.Drawing.Color.FromArgb(((int)(((byte)(244)))), ((int)(((byte)(243)))), ((int)(((byte)(234)))));
            this.editor.TabIndex = 0;
            this.editor.TextDrawStyle = Fireball.Windows.Forms.CodeEditor.TextDraw.TextDrawType.SingleBorder;
            this.editor.WhitespaceColor = System.Drawing.SystemColors.ControlDark;
            this.editor.Click += new System.EventHandler(this.editor_Click);
            this.editor.TextChanged += new System.EventHandler(this.editor_TextChanged);

            System.Drawing.Font font = new System.Drawing.Font("Courier New", 10);

            this.editor.Font = font;
            // 
            // document
            // 
            this.document.Lines = new string[] {
        ""};
            this.document.MaxUndoBufferSize = 1000;
            this.document.Modified = false;
            this.document.UndoStep = 0;
            // 
            // CodeTab
            // 
            this.ClientSize = new System.Drawing.Size(680, 383);
            this.Controls.Add(this.editor);
            this.DockableAreas = Fireball.Docking.DockAreas.Document;
            this.DoubleBuffered = true;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Name = "CodeTab";
            this.ShowIcon = false;
            this.ShowInTaskbar = false;
            this.TabText = "[ Document ]";
            this.Text = "[ Document ]";
            this.Load += new System.EventHandler(this.CodeTab_Load);
            this.ResumeLayout(false);

        }

        private void CodeTab_Load(object sender, EventArgs e)
        {
            
        }

        private void editor_TextChanged(object sender, EventArgs e)
        {

            this.TabText = this.editor.FileName + "*";
            

            /*if (this.Tag.GetType().Name == "OpenedFile")
            {
                this.TabText = "SHIT CHANGED";
           
                if (((OpenedFile)this.Tag).Saved == true)
                    this.TabText = this.TabText + "*";
                ((OpenedFile)this.Tag).Saved = false;
            }*/
        }

        private void editor_Click(object sender, EventArgs e)
        {
            
        }
    }
}
